package com.ruoyi.project.system.question.controller;

import java.util.List;

import com.ruoyi.project.system.question.service.IExamDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.question.domain.ExamDetail;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.text.Convert;

/**
 * 答题详情Controller
 * 
 * @author ruoyi
 * @date 2023-07-15
 */
@Controller
@RequestMapping("/system/question/detail")
public class ExamDetailController extends BaseController
{
    private String prefix = "system/question/detail";

    @Autowired
    private IExamDetailService examDetailService;

    @RequiresPermissions("system:question:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询答题详情列表
     */
    @RequiresPermissions("system:question:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamDetail examDetail)
    {
        startPage();
        List<ExamDetail> list = examDetailService.selectExamDetailList(examDetail);
        return getDataTable(list);
    }

    /**
     * 导出答题详情列表
     */
    @RequiresPermissions("system:question:detail:export")
    @Log(title = "答题详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamDetail examDetail)
    {
        List<ExamDetail> list = examDetailService.selectExamDetailList(examDetail);
        ExcelUtil<ExamDetail> util = new ExcelUtil<ExamDetail>(ExamDetail.class);
        return util.exportExcel(list, "答题详情数据");
    }

    /**
     * 新增答题详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存答题详情
     */
    @RequiresPermissions("system:question:detail:add")
    @Log(title = "答题详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamDetail examDetail)
    {
        return toAjax(examDetailService.insertExamDetail(examDetail));
    }

    /**
     * 修改答题详情
     */
    @RequiresPermissions("system:question:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ExamDetail examDetail = examDetailService.selectExamDetailById(id);
        mmap.put("examDetail", examDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存答题详情
     */
    @RequiresPermissions("system:question:detail:edit")
    @Log(title = "答题详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamDetail examDetail)
    {
        return toAjax(examDetailService.updateExamDetail(examDetail));
    }

    /**
     * 删除答题详情
     */
    @RequiresPermissions("system:question:detail:remove")
    @Log(title = "答题详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examDetailService.deleteExamDetailByIds(Convert.toLongArray(ids)));
    }
}